<?php
include('config.php');
session_start();
$autorizzato = $_SESSION['autorizzato'];
$villa = $_SESSION['villa'];
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">  
        <meta name="viewport" content="width=device-width, user-scalable=no">               
        <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.3.0/pure-min.css">
        <!-- <link rel="stylesheet" href="css/pure-min.css">-->

        <!--[if lte IE 8]>
        <link rel="stylesheet" href="css/main-grid-old-ie.css">
    <![endif]-->
        <!--[if gt IE 8]><!-->
        <link rel="stylesheet" href="css/main-grid.css">
        <!--<![endif]-->

        <!--[if lte IE 8]>
            <link rel="stylesheet" href="css/layouts/marketing-old-ie.css">
        <![endif]-->
        <!--[if gt IE 8]><!-->
        <link rel="stylesheet" href="css/layouts/marketing.css">
        <!--<![endif]-->
        <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
        <!-- <link rel="stylesheet" href="css/font-awesome.css">-->

        <title></title>
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
        <script src="js/jquery.tablesorter.js" type="text/javascript"></script>
    </head>
    <body> 
        <div class="header">
            <div class="home-menu pure-menu pure-menu-open pure-menu-horizontal pure-menu-fixed">
                <ul>
                    <li>
                        <form>
                            <input class="pure-menu-heading" type="text" id="search" placeholder="cerca...">
                        </form>
                    </li> 
                    <li>
                        <form class="pure-menu-heading" action="welcome.php" method="post">              
                            <button class="pure-button-primary" type="submit"><i class="fa fa-arrow-left"></i></button>                     
                        </form>
                    </li>  
                    <li>                                  
                        <button id="button_filtra_azienda" class="pure-button-primary"  onclick="mostraAziende()" type="submit"><i class="fa fa-filter">Aziende</i></button>                                             
                    </li>
                    <li>                                     
                        <button id="button_filtra_privati" class="pure-button-primary"  onclick="mostraPrivati()" type="submit"><i class="fa fa-filter">Privati</i></button>                                             
                    </li>     
                    <li>                                     
                        <button id="button_filtra_sposi" class="pure-button-primary" onclick="mostraSposi()" type="submit"><i class="fa fa-filter">Sposi</i></button>                                             
                    </li>   
                    <li>                                     
                        <button id="button_filtra_nessuno" class="pure-button-primary" onclick="mostraTutti()" type="submit"><i class="fa fa-filter">Tutti</i></button>                                             
                    </li> 
                </ul>
            </div>            
        </div>
        <p></p><div class="content-head">yuutr</div>

        <div class="content-subhead">
            <table class="pure-table pure-table-bordered tablesorter" id="myTable">
                <thead>
                    <tr>        
                        <th>Tipologia cliente</th>
                        <th>Nome Sposo</th>               
                        <th>Cognome Sposo</th>
                        <th>Tel Sposo</th>
                        <th>Email Sposo</th>
                        <th>Nome Sposa</th>
                        <th>Cognome Sposa</th>
                        <th>Tel Sposa</th>
                        <th>Email Sposa</th>
                        <th>Evento</th>
                        <th>Data Richiesta</th>
                        <th>Data Possibile</th>                        
                        <th>Data possibile #2</th>  
                        <th>Data possibile #2</th>
                        <th>Adulti</th>
                        <th>Bambini</th>
                        <th>Note</th>
                        <th>Email Contatto</th>
                        <th>Villa</th>        
                        <th>IVA Azienda</th>
                        <th>Azienda</th>
                        <th>Telefono Azienda</th>
                        <th>Email Azienda</th>
                        <th>Nome Privato</th>
                        <th>Cognome Privato</th>
                        <th>Telefono Privato</th>
                        <th>Email Privato</th>
                        <th>Registrazione</th>                          
                </thead>
                <tbody>
                    <?php
                    //echo $_SESSION['autorizzato'];

                    if ($villa == "tutte") {

                        $sql = "SELECT * FROM prenotazioni order by idprenotazioni";
                    } else {
                        $sql = "SELECT * FROM prenotazioni order by idprenotazioni where villa= '.$villa.'";
                    }
//echo $sql;
                    $result = mysql_query($sql);
                    if ($result) {
                        $count = mysql_num_rows($result);
                        if ($count > 0) {

                            while ($row = mysql_fetch_array($result)) {
                                echo '<tr>';
                                echo '<td>' . $row['tipologia_cliente'] . '</td>';
                                echo '<td>' . $row['nome_sposo'] . '</td>';
                                echo '<td>' . $row['cognome_sposo'] . '</td>';
                                echo '<td>' . $row['tel_sposo'] . '</td>';
                                echo '<td>' . $row['email_sposo'] . '</td>';
                                echo '<td>' . $row['nome_sposa'] . '</td>';
                                echo '<td>' . $row['cognome_sposa'] . '</td>';
                                echo '<td>' . $row['tel_sposa'] . '</td>';
                                echo '<td>' . $row['email_sposa'] . '</td>';
                                echo '<td>' . $row['tipologia_evento'] . '</td>';
                                echo '<td>' . $row['data_interessata'] . '</td>';
                                echo '<td>' . $row['data_possibile'] . '</td>';
                                echo '<td>' . $row['data_possibile2'] . '</td>';
                                echo '<td>' . $row['data_possibile3'] . '</td>';
                                echo '<td>' . $row['ospiti_adulti'] . '</td>';
                                echo '<td>' . $row['ospiti_bambini'] . '</td>';
                                echo '<td>' . $row['note'] . '</td>';
                                echo '<td>' . $row['email_contatto'] . '</td>';
                                echo '<td>' . $row['villa'] . '</td>';
                                echo '<td>' . $row['p_iva'] . '</td>';
                                echo '<td>' . $row['nome_azienda'] . '</td>';
                                echo '<td>' . $row['tel_azienda'] . '</td>';
                                echo '<td>' . $row['email_azienda'] . '</td>';
                                echo '<td>' . $row['nome_privato'] . '</td>';
                                echo '<td>' . $row['cognome_privato'] . '</td>';
                                echo '<td>' . $row['tel_privato'] . '</td>';
                                echo '<td>' . $row['email_privato'] . '</td>';
                                echo '<td>' . $row['timestamp'] . '</td>';
                            }
                        }
                    }
                    ?>
                </tbody>
            </table>     
        </div>
        <script>
            $(document).ready(function()
            {
                $("#myTable").tablesorter();
                $("#search").on("keyup", function() {
                    var value = $(this).val();

                    $("table tr").each(function(index) {
                        if (index != 0) {

                            $row = $(this);

                            var id = $row.find("td:first").text();

                            if (id.indexOf(value) != 0) {
                                $(this).hide();
                            }
                            else {
                                $(this).show();
                            }
                        }
                    });
                });
            }
            );
        </script>  

        <script type="text/javascript">
            function mostraAziende() {
                console.log('mostra azienda');

                $("#myTable tr td:first-child").each(function() {
                    var cellText = $.trim($(this).text());
                    $(this).parent().show();

                });


                $("#myTable tr td:first-child").each(function() {
                    var cellText = $.trim($(this).text());
                    if (cellText === 'Sposi' || cellText === 'Privato') {
                        $(this).parent().hide();
                    }
                });

            }
        </script>
        <script type="text/javascript">
            function mostraPrivati() {
                console.log('mostra privati');

                $("#myTable tr td:first-child").each(function() {
                    var cellText = $.trim($(this).text());
                    $(this).parent().show();

                });

                $("#myTable tr td:first-child").each(function() {
                    var cellText = $.trim($(this).text());
                    if (cellText === 'Azienda' || cellText === 'Sposi') {
                        $(this).parent().hide();
                    }
                });

            }
        </script>
        <script type="text/javascript">
            function mostraSposi() {
                console.log('mostra Sposi');

                $("#myTable tr td:first-child").each(function() {
                    var cellText = $.trim($(this).text());
                    $(this).parent().show();

                });

                $("#myTable tr td:first-child").each(function() {
                    var cellText = $.trim($(this).text());
                    if (cellText === 'Azienda' || cellText === 'Privato') {
                        $(this).parent().hide();
                    }
                });

            }
        </script>
        <script type="text/javascript">
            function mostraTutti() {
                console.log('mostra tutti');

                $("#myTable tr td").each(function() {
                    var cellText = $.trim($(this).text());
                    $(this).parent().show();

                });

            }
        </script>

    </body>
</html>
